#ifndef __SERVER_H__
#define __SERVER_H__

#include <time.h>
#include <list>
#include "Client.h"
#include "Host.h"
#include "Threadpool.h"
#include "Mutex.h"

class Server
{
public:
	Server();
	unsigned int		Start(unsigned short int port, const std::string& address);
	IEmpacter*			GetEmpacter();
	std::list<Client*>* GetClient();
	IMutex*				GetMutexClientListBrowse();
	IMutex*				GetMutexClientListModification();
	void				AccesClientList(bool need);
	bool				ClientListIsAccessed();
	
	unsigned int		_octIn;
	unsigned int		_octOut;

private:
	static void			AcceptClient(void* server);
	static void			SelectReceive(void* data);
	void				RemoveClient(Client* client);
	void				AddClient(Client* client);
	std::list<Client*>	_clientList;
	IMutex*				_mtxClientListModification;
	IMutex*				_mtxClientListBrowse;
	unsigned int		_clientListNbAcces;
	Network::Host*		_cnt;
	IEmpacter*			_emp;
	struct info_select
	{
		Server* server;
		Client* client;
	};
};

#endif //__SERVER_H__